﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Windows.Media.Imaging;

namespace MetroHome
{
    public class WidgetManager
    {
        public List<Widget> Widgets { get; private set; }

        public WidgetManager()
        {
            Widgets = new List<Widget>();
        }

        public void FindWidgets()
        {
            if (Directory.Exists(Metro.Core.E.Path) && Directory.GetDirectories(Metro.Core.E.Path).Length > 0)
            {
                foreach (string dir in Directory.GetDirectories(Metro.Core.E.Path))
                {
                    var d = new DirectoryInfo(dir);
                    var file = string.Format("{0}\\{1}\\{1}.dll", Metro.Core.E.Path, d.Name);
                    if (File.Exists(file))
                    {
                        var w = new Widget();
                        w.Initalize(file);
                        if (!w.HasErrors)
                        {
                            Widgets.Add(w);

                            /*if (App.Sett.LoadedWidgets != null && App.Sett.LoadedWidgets.Contains(w.WidgetName))
                            {
                                w.Load();
                            }*/
                        }
                    }
                }
            }
        }
    }
}
